<template>
	<view>
		注册页面
		<button @tap="register">注册</button>
		<button @tap="uploadAvatar">上传头像</button>
		<button @tap="uploadAvatar2">上传头像2</button>
		<image :src="avatarURL" mode=""></image>
	</view>
</template>

<script>
	import {register as registerApi} from '@/api/user/index.js'
	import baseURL from '@/api/baseUrl.js'
	export default {
		data() {
			return {
				avatarURL:''
			};
		},
		methods:{
			register(){
				// uni.$emit("onMsg",{msg:'来自与注册页面的数据'})
				// uni.$off('onMsg')
				
				// uni.$emit('onEvent','你好')
				
				registerApi({
							// "birthday": "2022-12-05 2:45:49",
							// "city": "郑州",
							// "email": "123@163.com",
							// "growth": 100,
							// "historyIntegration": 1000,
							"icon": this.avatarURL,
							// "id": "string", // 注册时没有，后台生成
							// "integration": 0,
							// "isDisabled": 0, // 是否禁用 1（true）已禁用， 0（false）未禁用 ,
							// "memberLevelId": "string",
							// "modifyTime": "2022-12-05T02:45:49.240Z",
							"nickname": "小六子",
							"password": "123456",
							// "personalizedSignature": "好好学习，天天向上",
							"phone": "13588889898",
							// "realname": "李四",
							// "sex": 0,// ：0->未知；1->男；2->女 ,3,4,5，
							// "sourceType": 0,
							// "status": 0, // 帐号启用状态:0->禁用；1->启用 ,
							"username": "李逵", // 用于登录
							// "wxOpenId": "string"
						})
			},
			uploadAvatar(){
				var _this = this
				// 1. 先选择图片
				uni.chooseImage({
					count:1,
					sourceType:["camera","album"],
					sizeType:["original"],
					success(res) {
						// console.log(res);
						const tempFilePath = res.tempFilePaths[0]
						// 2. 上传
						uni.uploadFile({
							url: baseURL + '/lejuClient/login/uploadAvatar',
							filePath:tempFilePath,
							name:'file',
							timeout:5000,
							success(res2){
								// console.log(res2);
								const avatarURL = JSON.parse(res2.data).data.fileUrl
								_this.avatarURL = avatarURL
							}
						})
					}
				})
				
			},
			uploadAvatar2(){
				// #ifdef MP-WEIXIN
				uni.chooseMedia({
					count:1,
					mediaType:['image'],
					sourceType:["album","camera"],
					sizeType:["original"],
					success(res){
						console.log(res);
					}
				})
				// #endif
		
			}
		},

	}
</script>

<style lang="scss" scoped>

</style>
